
<template>
  <el-form :model="loginForm" :rules="loginFormRules" ref="loginFormRef"  class="login-container" label-position="left"
            label-width="0px">
    <el-form-item>
      <h3 class="login_title">用户登录</h3>
    </el-form-item>
    <el-form-item prop="username">
      <el-input type="text" id="zh" v-model="loginForm.username"  auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input type="password" id="mm" v-model="loginForm.password"  auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="login()">登录</el-button>
      <el-button type="info" @click="resetloginForm()">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
/* eslint-disable */
export default {
  data(){
    return{
      //登陆表单数据
      loginForm:{
        username:'admin',
        password:'123456'
      },
      //表单验证规则对象
      loginFormRules:{
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    //重置
    resetloginForm(){
      this.$refs.loginFormRef.resetFields();
    },
    //登陆
    login(){
      this.$refs.loginFormRef.validate(valid =>{
        if(!valid) return;
        this.$http.post("login",this.loginForm).then(res =>{
          if(res.data.meta.status !== 200) return this.$message.error("登陆失败");
          this.$message({message:"登陆成功",type:"success"});
          //1.登陆成功后，后台会返回一个token，保存到客户端sessionStorage中
          window.sessionStorage.setItem("token",res.data.data.token);
          this.$router.push("/home");

        })

      })
    }
  }
}
</script>

<style scoped lang="less">
  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }
.login_box{
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}
  .avatar_box{
    height: 130px;
    width: 130px;
    border: 1px solid #eee;
    border-radius: 50%;
    padding: 10px;
    box-shadow: 0 0 10px #dddddd;
    position: absolute;
    left: 50%;
    transform: translate(-50%,-50%);
    background-color: #ffffff;
    img{
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background-color: #eeeeee;
    }
  }
</style>
